from datetime import datetime
import tushare as ts


ts.set_token('5de4fce4d8cf12289b63dff3fd36a0f8887e06b04d838f4e33085919')
pro = ts.pro_api()


# 查询当前所有正常上市交易的股票列表
def get_all_base():
    data = pro.stock_basic(exchange='', list_status='L', fields='ts_code,symbol,name,area,industry,list_date')
    print(data)
    data.to_csv('stock_base_info.csv', index=False, encoding='utf-8-sig')


def get_daily(ts_codes,start_date='20231101',end_date=None):
    # 如果end_date没有提供，使用当前日期
    if end_date is None:
        current_date = datetime.now()
        end_date = current_date.strftime('%Y%m%d')
    df = pro.daily(ts_code=ts_codes, start_date=start_date, end_date=end_date)
    df.to_csv('stock_base_daily.csv', index=False, encoding='utf-8-sig')
 #   df = pro.daily(ts_code='000001.SZ', start_date='20180701', end_date='20180718')
    # 多个股票
    # df = pro.daily(ts_code='000001.SZ,600000.SH', start_date='20180701', end_date='20180718')


if __name__ == '__main__':
    get_daily('000628.SH',start_date='20231101',end_date='20240229')
